package com.zhkj.txg.module.find.adapter

import android.view.View
import android.widget.ImageView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.module.LoadMoreModule
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.zhkj.txg.R
import com.zhkj.txg.module.find.entity.ArticleCommentEntity
import com.zhkj.lib.utils.AccountManager
import com.zhkj.txg.utils.ImageUtils

class FindCommentAdapter :
    BaseQuickAdapter<ArticleCommentEntity, BaseViewHolder>(R.layout.item_find_article),
    LoadMoreModule {

    private val userId = AccountManager.getUserId()

    init {
        addChildClickViewIds(R.id.viewFindCommentLike, R.id.tvFindArticleCommentDelete)
    }

    override fun convert(helper: BaseViewHolder, item: ArticleCommentEntity) {
        val imageView = helper.setText(R.id.tvFindCommentLike, item.likes.toString())
            .setText(R.id.tvFindArticleCommentName, item.nickname)
            .setText(R.id.tvFindArticleCommentContent, item.content)
            .setText(R.id.tvFindArticleCommentDate, item.createTime)
            .setVisible(R.id.tvFindArticleCommentDelete, userId == item.userId.toLong())
            .getView<ImageView>(R.id.ivFindArticleComment)
        ImageUtils.loadCircleImage(context, imageView, item.avatar)
        helper.getView<View>(R.id.viewFindCommentLike).isSelected = item.likeArticle
    }
}